#include "MeshLoader.h"

using  namespace DirectX;

MeshLoader::MeshLoader(void) : FOLDER("Models/")
{
}


MeshLoader::~MeshLoader(void)
{
}

MeshLoader& MeshLoader::GetInstance()
{
  static MeshLoader instance;
  return instance;
}

MeshDesc* MeshLoader::LoadMeshFromFile(std::string fileName)
{
  Vertex* vertices = 0;
  WORD* indices = 0;
  unsigned int numVertices = 0;
  unsigned int numIndices = 0;

  MeshDesc* meshDesc = new MeshDesc();

  if(m_meshMap[fileName] != 0)
  {
    
    memcpy(meshDesc, m_meshMap[fileName], sizeof(MeshDesc));

    /*meshDesc->Vertices= m_meshMap[fileName]->Vertices;
    meshDesc->Indices = m_meshMap[fileName]->Indices;
    meshDesc->NumVertices = m_meshMap[fileName]->NumVertices;
    meshDesc->NumIndices = m_meshMap[fileName]->NumIndices;
    meshDesc->NumMaterials = m_meshMap[fileno*/
  }
  else
  {
    if(FAILED(m_objLoader.Create(FOLDER + fileName)))
      return 0;

    meshDesc->Indices = m_objLoader.GetIndices();
    meshDesc->NumIndices = m_objLoader.GetNumIndices();
    meshDesc->NumVertices = m_objLoader.GetNumVertices();
    meshDesc->Vertices= m_objLoader.GetVertices();  
    meshDesc->Materials = m_objLoader.GetMaterials();
    meshDesc->NumMaterials = m_objLoader.GetNumMaterials();
    m_meshMap[fileName] = meshDesc;
    
  }

  return meshDesc;
}
